package com.burt.springcloudeurekaconsumerdemo.controller;

import java.util.Collection;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.burt.springcloudeurekaconsumerdemo.client.UserClient;

/**
 * DcController
 * 
 * @author burt
 * @date 2018/7/16 19:20
 */
@RestController
public class UserController {

    private final RestTemplate restTemplate;

    private final UserClient   userClient;

    @Autowired
    public UserController(RestTemplate restTemplate, UserClient userClient) {
        this.restTemplate = restTemplate;
        this.userClient = userClient;
    }

    @GetMapping("/find/all")
    public Collection findAllUser() {
        return restTemplate.getForObject("http://user-service-provider/find/all", Collection.class);
    }

    @GetMapping("/find/all/v2")
    public Collection findAllUser2() {
        System.out.println("/find/all/v2");
        return userClient.findAll();
    }
}
